package controllers

import (
	"github.com/astaxie/beego"
	"xiaoercaidan/publicResources/models"
	"github.com/astaxie/beego/httplib"
	"strconv"
	"encoding/json"
)

type GoodsController struct {
	beego.Controller
}

// @Title GoodsDetail
// @Description 菜品详情
// @Param   goodsId    patch int64  true  string       "菜品ID"
// @router /goodsDetail [get]
func (this *GoodsController) GoodsDetail()  {
	hostStr := "http://"+beego.AppConfig.String("basehost")+":"+beego.AppConfig.String("baseport")
	var goodsId,_ = this.GetInt64("goodsId",0)
	var BaseResult = new(models.BaseResult)
	if(goodsId <= 0){
		BaseResult.Code = 100
		BaseResult.Msg = "goodsId参数不正确"
		this.Data["json"] = &BaseResult
		this.ServeJSON()
		return
	}
	req := httplib.Get(hostStr+"/v1/apis/goods/queryGoodsDetail")
	req.Param("id", strconv.FormatInt(goodsId, 10))
	resp, err := req.String()

	if (err == nil) {
		var mapStr = make(map[string]interface{})

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	}

	this.ServeJSON()
}